package com.quyunshuo.module.home.fragment.home

import androidx.fragment.app.activityViewModels
import androidx.lifecycle.lifecycleScope
import com.quyunshuo.edwinmusictwo.base.BaseApplication
import com.quyunshuo.edwinmusictwo.base.utils.BarUtils
import com.quyunshuo.edwinmusictwo.common.ui.BaseFragment
import com.quyunshuo.module.home.activity.main.SharedViewModel
import com.quyunshuo.module.home.databinding.HomeFragmentHomeBinding
import com.quyunshuo.module.home.fragment.compose.LatelyMusicPage
import com.quyunshuo.module.home.fragment.compose.LocalMusicPage
import com.quyunshuo.module.home.music.MusicPlayer
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch

/**
 * @author DBoy 2021/7/6 <p>
 * - 文件描述 : 测试fragment
 */
@AndroidEntryPoint
class HomeFragment : BaseFragment<HomeFragmentHomeBinding, SharedViewModel>() {
    private val TAG = "HomeFragment"

    //    override val mViewModel by viewModels<HomeViewModel>()
    override fun createVB() = HomeFragmentHomeBinding.inflate(layoutInflater)
    override val mViewModel: SharedViewModel by activityViewModels()


    override fun HomeFragmentHomeBinding.initListener() {


    }

    override fun HomeFragmentHomeBinding.initView() {
        BarUtils.setStatusBarLightMode(requireActivity(), false)
        //先查询本地音乐，然后这里只展示6秒数据，想看更多，就进入二级页面。

        mBinding.latelyMusicCompose.setContent {
            LatelyMusicPage(vm=mViewModel){music,index->
                MusicPlayer.init(BaseApplication.context, music!!,index)
                mViewModel.setCurrentMusic(music)

            }
        }

    }

    override fun onDestroyView() {
        super.onDestroyView()
    }

    override fun initObserve() {
        lifecycleScope.launch {
            mViewModel.localMusic.collect {
                mBinding.localMusicCompose.setContent {
                    LocalMusicPage(it, vm = mViewModel) {music,index->
                        MusicPlayer.init(BaseApplication.context, music!!,index)
                        mViewModel.setCurrentMusic(music)
                    }
                }
            }
        }
        lifecycleScope.launch {

        }
    }

    override fun initRequestData() {
    }



}